

package com.hazelcast.security.permission;

import java.io.Serial;

public class UserCodeNamespacePermission extends InstancePermission {
    @Serial
    private static final long serialVersionUID = 1L;

    private static final int USE = 4;
    private static final int ALL = CREATE | DESTROY | USE;

    public UserCodeNamespacePermission(String namespace, String... actions) {
        super(namespace, actions);
    }

    @Override
    protected int initMask(String[] actions) {
        int mask = NONE;
        for (String action : actions) {
            if (ActionConstants.ACTION_ALL.equals(action)) {
                return ALL;
            }

            if (ActionConstants.ACTION_CREATE.equals(action)) {
                mask |= CREATE;
            } else
                if (ActionConstants.ACTION_DESTROY.equals(action)) {
                    mask |= DESTROY;
                } else
                    if (ActionConstants.ACTION_USE.equals(action)) {
                        mask |= USE;
                    }
        }
        return mask;
    }
}
